<?php
if( ! defined( 'XOOPS_ROOT_PATH' ) ) die('root path not defined');

$mydirname = basename( dirname( dirname( __FILE__ ) ) );
defined('RBTOOL_FUNCTIONS') || include XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/include/functions.php';
rbtool_load_object();

class RbtoolProject extends RbCrud
{
	function __construct()
	{
		$this->initVar('pid', XOBJ_DTYPE_INT, null, false);
		$this->initVar('name', XOBJ_DTYPE_TXTBOX, null, false, 150);
		$this->initVar('dirname', XOBJ_DTYPE_TXTBOX, null, false, 25);
		$this->initVar('description', XOBJ_DTYPE_TXTBOX, null, false, 255);
		$this->initVar('version', XOBJ_DTYPE_TXTBOX, null, false, 10);
		$this->initVar('author', XOBJ_DTYPE_TXTBOX, null, false, 150);
		$this->initVar('credits', XOBJ_DTYPE_TXTBOX, null, false, 150);
		$this->initVar('license', XOBJ_DTYPE_TXTBOX, null, false, 150);
		$this->initVar('created', XOBJ_DTYPE_INT, 0, false);
		$this->initVar('updated', XOBJ_DTYPE_INT, time(), false);
		$this->initVar('weight', XOBJ_DTYPE_INT, 0, false);
		$this->initVar('hasmain', XOBJ_DTYPE_INT, 0, false);
		$this->initVar('hasadmin', XOBJ_DTYPE_INT, 0, false);
		$this->initVar('adminindex', XOBJ_DTYPE_TXTBOX, null, false, 150);
		$this->initVar('adminmenu', XOBJ_DTYPE_TXTBOX, null, false, 150);

	}
	
	function RbtoolProject()
	{
		$this->__construct();
	}
}

class RbtoolProjectHandler extends RbCrudHandler
{
	function __construct(&$db) 
    {
        parent::__construct($db, 'rbtool_project', 'RbtoolProject', 'pid', 'weight DESC');
    }
    
    function RbtoolProjectHandler(&$db)
    {
        $this->__construct($db);
    }
	
	function deleteRow($primary = 0, $force = TRUE)
	{
		if( !$this->isExists($primary) ) {
			$this->setErrors(__CLASS__.'::'.__FUNCTION__.' primary key is exists');
			return FALSE;
		}
		$object = $this->get($primary);
		$dirname = $object->getVar('dirname');
		rbtool_rmdir(RBTOOL_COPY_PATH.'/'.$dirname);
		return $this->delete($object, $force);
	}
}
?>